home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / multi_re < prev    next >
Internet Message Format  |  1995-03-31  |  5KB

  1. From @VM.CC.PURDUE.EDU:SCHUTZ@Rollins.Bitnet  Tue Jan 29 19:10:57 1991
  2. Received: from zoo.ecn.purdue.edu by en.ecn.purdue.edu (5.65/1.30jrs)
  3.     id AA17776; Tue, 29 Jan 91 19:10:57 -0500
  4. From: @VM.CC.PURDUE.EDU:SCHUTZ@Rollins.Bitnet
  5. Received: from vm.cc.purdue.edu by zoo.ecn.purdue.edu (5.65/1.30jrs)
  6.     id AA05157; Tue, 29 Jan 91 19:10:52 -0500
  7. Received: from Rollins.Bitnet (SCHUTZ) by PURCCVM.BITNET (Mailer R2.07) with
  8.  BSMTP id 7264; Tue, 29 Jan 91 19:10:42 EST
  9. Date: Tue, 29 Jan 91 16:22 EST
  10. Subject: Schutz's REGR.TXT for HP48SX from Compuserve
  11. To: wscott@ecn.purdue.edu
  12. Message-Id: <C8F223CA17BF000371@Rollins.Bitnet>
  13. X-Envelope-To: wscott@ecn.purdue.edu
  14. X-Vms-To: IN%"wscott@ecn.purdue.edu"
  15. Status: OR
  16.  
  17. %%HP: T(3)A(D)F(.);
  18. @
  19. @ REGR -- a multivariate statistical regression utility.
  20. @
  21. @ Eric Schutz, Rollins College, Winter Park, FL 32789
  22. @ (bitnet: SCHUTZ at ROLLINS)
  23. @ January, 1991
  24. @
  25. @ This program enables the HP48SX to estimate the "best fit" or linear
  26. @ regression of a dependent variable on <several> independent variables --
  27. @ extending the calculator's built-in bivariate regression capability to a
  28. @ <multivariate> capability. Enter as input on the stack:
  29. @
  30. @                  2:      'name'
  31. @                  1:      {list}
  32. @
  33. @ where 'name' is the name of the data input matrix and {list} is a list of
  34. @ the column-numbers in 'name' that are the regression variables, beginning
  35. @ with the dependent-variable column. Thus << FRED { 2 1 4 6 } REGR >> would
  36. @ regress column-2 (the dependent-variable) on columns-1, -4 and -6 (the
  37. @ independent-variables, respectively) in the input matrix FRED.
  38. @
  39. @ NOTE: (i) REGR uses the statistics data matrix \GSDAT: be sure you do NOT
  40. @ have any data stored in that matrix that you don't mind losing! (ii) Be sure
  41. @ there ARE enough "degrees of freedom" for the calculations involved:
  42. @ the number of observations in your data set must exceed the number of
  43. @ variables in the regression, and there must be no "perfect multi-
  44. @ collinearity" among the independent variables.
  45. @
  46. @ REGR leaves the input-data matrix itself unaffected, it uses no flags, and
  47. @ it leaves unaffected any objects already on the stack. The output of the
  48. @ REGR program consists of the following variables that are created in the
  49. @ current directory:
  50. @
  51. @     B        -- array of coefficient estimates, beginning with the intercept
  52. @                 term, then the slope terms in the same order as in the input
  53. @                 list.
  54. @
  55. @     \Gs.B    -- array of standard errors of the corresponding coefficient
  56. @                 estimates in B.
  57. @
  58. @     T.B      -- array of t-statistics of the corresponding coefficient
  59. @                 estimates in B.
  60. @
  61. @     P.B      -- array of P-values of the corresponding coefficient estimates
  62. @                 in B.
  63. @
  64. @     R2       -- "R-squared" of the regression.
  65. @
  66. @     R2J      -- adjusted "R-squared" of the regression.
  67. @
  68. @     \Gs2     -- square of the standard error of the regression.
  69. @
  70. @     DF       -- degrees of freedom.
  71. @
  72. @     F        -- F-statistic for the regression.
  73. @
  74. @     P.F      -- P-value of the F-statistic for the regression.
  75. @
  76. @     TSS      -- total sum of squares for ANOVA.
  77. @
  78. @     ESS      -- explained sum of squares for ANOVA.
  79. @
  80. @     RSS      -- residual sum of squares for ANOVA.
  81. @
  82. @     DW       -- Durbin-Watson statistic.
  83. @
  84. @     VC.B     -- variance-covariance matrix of the coefficient estimates in B.
  85. @
  86. @     RESID    -- array of residuals from the regression-line.
  87. @
  88. @     PRED     -- array of predicted-values of the dependent-variable.
  89. @
  90. @
  91. \<< \-> MNAME CNUMS
  92.   \<< CL\GS MNAME RCL
  93. SIZE 1 GET \-> N
  94.     \<< CNUMS 1 GET \->
  95. DV
  96.       \<< 1 N
  97.         FOR I MNAME
  98. RCL { I DV } GET
  99.         NEXT { N 1
  100. } \->ARRY 'Y' STO 1 N
  101.         START 1
  102.         NEXT N
  103. \->ARRY \GS+
  104.       \>> CNUMS SIZE
  105. 2 SWAP
  106.       FOR J CNUMS J
  107. GET \-> CN
  108.         \<< 1 N
  109.           FOR I
  110. MNAME RCL { I CN }
  111. GET
  112.           NEXT N
  113. \->ARRY \GS+
  114.         \>>
  115.       NEXT RCL\GS TRN
  116. 'X' STO CL\GS X TRN X
  117. * INV X TRN Y * *
  118. 'B' STO X B *
  119. 'PRED' STO Y PRED -
  120. 'RESID' STO RESID
  121. TRN RESID * N CNUMS
  122. SIZE - / ARRY\-> DROP
  123. '\Gs2' STO \Gs2 X TRN X
  124. * INV * 'VC.B' STO
  125. 1 CNUMS SIZE
  126.       FOR J 'VC.B'
  127. RCL { J J } GET \v/
  128.       NEXT CNUMS
  129. SIZE \->ARRY '\Gs.B'
  130. STO 1 CNUMS SIZE
  131.       FOR J 'B' RCL
  132. J GET '\Gs.B' RCL J
  133. GET /
  134.       NEXT CNUMS
  135. SIZE \->ARRY 'T.B'
  136. STO 1 CNUMS SIZE
  137.       FOR J 'T.B'
  138. RCL J GET ABS N
  139. CNUMS SIZE - SWAP
  140. UTPT
  141.       NEXT CNUMS
  142. SIZE \->ARRY 'P.B'
  143. STO Y \GS+ MEAN \-> \GmY
  144.       \<< B TRN X TRN
  145. * X * B * ARRY\->
  146. DROP N \GmY SQ * - Y
  147. TRN Y * ARRY\-> DROP
  148. N \GmY SQ * - / 'R2'
  149. STO 1 1 R2 - N 1 -
  150. * N CNUMS SIZE - /
  151. - 'R2J' STO CL\GS
  152. RESID ARRY\-> 1 GET 1
  153. - 1 2 \->LIST \->ARRY
  154. SWAP DROP RESID
  155. ARRY\-> SWAP DROP 1
  156. GET 1 - 1 2 \->LIST
  157. \->ARRY -1 * - STO\GS
  158. TOT RESID TRN RESID
  159. * ARRY\-> DROP DUP
  160. 'RSS' STO / 'DW'
  161. STO CL\GS Y DUP STO\GS
  162. TRN Y * ARRY\-> DROP
  163. N MEAN SQ * - 'TSS'
  164. STO TSS RSS - 'ESS'
  165. STO N CNUMS SIZE -
  166. 'DF' STO ESS CNUMS
  167. SIZE 1 - / RSS DF /
  168. / 'F' STO CNUMS
  169. SIZE 1 - DF F UTPF
  170. 'P.F' STO { B \Gs.B
  171. T.B P.B R2 R2J \Gs2
  172. DF F P.F TSS ESS
  173. RSS DW VC.B RESID
  174. PRED } ORDER { X Y
  175. } PURGE CL\GS
  176.       \>>
  177.     \>>
  178.   \>>
  179. \>>
  180.  
  181.  
  182.